package com.zrrd.product.controller;

import com.zrrd.common.result.Result;
import com.zrrd.model.product.*;
import com.zrrd.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    //查询一级分类
    @GetMapping("/getCategory1")
    public Result<List<BaseCategory1>> getCategory1() {
        return Result.ok(categoryService.getCategory1());
    }

    //查询二级分类
    @GetMapping("/getCategory2/{category1Id}")
    public Result<List<BaseCategory2>> getCategory2(@PathVariable Long category1Id){
        return Result.ok(categoryService.getCategory2(category1Id));
    }

    //查询二级分类
    @GetMapping("/getCategory3/{category2Id}")
    public Result<List<BaseCategory3>> getCategory23(@PathVariable Long category2Id){
        return Result.ok(categoryService.getCategory3(category2Id));
    }

    //根据分类ID查询属性以及属性值
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result<List<BaseAttrInfo>> getBaseAttrInfo(@PathVariable("category1Id") Long category1Id,
                                                      @PathVariable("category2Id") Long category2Id,
                                                      @PathVariable("category3Id") Long category3Id){
        return Result.ok(categoryService.getBaseAttrInfo(category1Id,category2Id,category3Id));
    }

    //新增平台属性
    @PostMapping("/saveAttrInfo")
    public Result<String> saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        categoryService.saveAttrInfo(baseAttrInfo);
        return Result.ok("添加平台属性成功");
    }

    //根据平台属性id获取属性值列表
    @GetMapping("/getAttrValueList/{attrId}")
    public Result<List<BaseAttrValue>> getAttrValueList(@PathVariable("attrId") Long attrId){
        return Result.ok(categoryService.getAttrValueList(attrId));
    }

    //获取所有的销售属性
    @GetMapping("/baseSaleAttrList")
    public Result<List<BaseSaleAttr>> baseSaleAttrList(){
        return Result.ok(categoryService.getBaseSaleAttrList());
    }
}
